package com.AFH.test;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;

public class Surprise extends Sprite implements Runnable{
	
	String surpriseStr = null;
	Rect surpriseRect=null;
	int surpriseRandom;
	int count=20;
	UserProfile gameProfile;
	boolean flag=false;
	public Surprise(UserProfile gameProfile){
		speed=0;
		currentSegment=0;
		currentFrame=0;
		flag=true;
		surpriseRandom = GameData.rnd.nextInt(4);
		int surpriseX = GameData.rnd.nextInt(8) * 80 + 20;
		int surpriseY = GameData.rnd.nextInt(4) * 80 + 20;
		surpriseRect = new Rect(surpriseX, 80 + surpriseY,
		surpriseX + 60, 80 + surpriseY + 60);
		this.gameProfile=gameProfile;
		
	}
	
	public void surpriseCatched(){
		setCurrentSegment(1);
		switch (surpriseRandom) {
		case 0:
			surpriseStr = GameData.GetBomb;
			gameProfile.BombNumber++;
			break;
		case 1:
			int moneybonus = (GameData.rnd.nextInt(5) + 1) * 10;
			surpriseStr = GameData.GetMoney + " " + moneybonus + " Gold!";
			gameProfile.Money += moneybonus;
			break;
		case 2:
			int moneypunish = (GameData.rnd.nextInt(5) + 1) * 10;
			surpriseStr = GameData.lostMoney + " " + moneypunish
					+ " Gold!";
			gameProfile.Money -= moneypunish;
			break;
		case 3:
			int scorebonus = (GameData.rnd.nextInt(5) + 1) * 100;
			surpriseStr = GameData.GetScore + " " + scorebonus + " Score!";
			gameProfile.score += scorebonus;
			break;
		}
	}
	
	@Override
	public void drawself(Canvas canvas){
		
		Paint paint_surprise = new Paint();
		paint_surprise.setColor(Color.RED);
		paint_surprise.setTextSize(20f);
		int ImgIndex = animationList.get(currentSegment)[currentFrame];
		BitmapManager.DrawGameUIResource(ImgIndex, canvas, surpriseRect.left, surpriseRect.top, null);
		
		if (surpriseStr != null)
		{
			Paint paint = new Paint();
		    paint.setColor(Color.BLACK);
		    paint.setAlpha(0x40);
			canvas.drawRect(0, 0, 800, 80, paint);
			canvas.drawText(surpriseStr, 500, 40, paint_surprise);
		}
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub
		while(flag){
			if(count>0)count--;
			else flag=false;
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
	}
	
	
}
